package com.bm.specialvehiclefordispatcher.logics;

import com.bm.corelibs.logic.BaseLogic.NListener;
import com.bm.specialvehiclefordispatcher.bean.BaseData;
import com.bm.specialvehiclefordispatcher.constants.Urls;

public class OrderManager extends BaseManager {

	public void getOrderDetail(long id, NListener<BaseData> l) {
		logic.edit().resetAll().addParam("orderId", id + "").setBaseClass(BaseData.class).setUrl(Urls.GET_ORDER).setListener(l);
		logic.doPost();
//		BaseData baseData = new BaseData();
//		baseData.status = Constant.STATUS_OK;
//		MapData mapData = new MapData();
//
//		Order order = new Order();
//		order.id = 0;
//		order.status = 1;
//
//		order.orderNum = "2015023251544";
//		order.appointmentTime = "2015-08-19 09:00";
//		order.style1 = new TruckStyle1(1, "砼车");
//		order.count = 12;
//		order.volume = 600;
//		order.sumPrice = 18000;
//		order.conditionName = "运输距离";
//		order.condition = "30公里以内";
//
//		Station station = new Station();
//		station.name = "武汉新中环建材有限公司";
//		station.addAddress = "武汉市汉阳区汉阳大道孟家铺特1号";
//
//		Dispatcher dispatcher = new Dispatcher();
//		dispatcher.name = "王玉玺";
//		dispatcher.phone = "13000000000";
//
//		order.dispatcher = dispatcher;
//		order.station = station;
//
//		List<OrderLog> orderLogs = new ArrayList<OrderLog>();
//		for (int i = 0; i < 10; i++) {
//			OrderLog log1 = new OrderLog();
//			Owner owner1 = new Owner();
//			Truck truck1 = new Truck();
//			truck1.style1 = new TruckStyle1(1, "砼车");
//			truck1.style2 = new TruckStyle2(1, "12方");
//			truck1.licenseplateNum = "鄂A123***";
//			owner1.name = "小张" + i;
//			owner1.icon = "https://d13yacurqjgara.cloudfront.net/users/109605/screenshots/2152255/lion.png";
//			owner1.finishedCount = 20;
//			owner1.phone = "13000000000";
//			owner1.score = 3.5;
//			log1.truck = truck1;
//			log1.owner = owner1;
//			OrderStatus status = new OrderStatus();
//			status.id = i + 1;
//			log1.status = status;
//			log1.addStatus = "";
//			orderLogs.add(log1);
//		}
//		order.orderLogs = orderLogs;
//
//		mapData.orderInfo = order;
//		baseData.data = mapData;
//		l.onResponse(baseData);
	}

	public void getFirst(String id, int type, NListener<BaseData> l) {
		page.pageNo = 1;
		getList(id, type, l);
	}

	public void getNext(String id, int type, NListener<BaseData> l) {
		page.pageNo++;
		System.out.println(page.pageNo + "--" + page.pageCount);
		if (page.pageNo <= page.pageCount)
			getList(id, type, l);
		else
			l.onAllPageLoaded(page.pageNo, page.pageCount);
	}

	protected void getList(String id, int type, NListener<BaseData> l) {
		logic.edit().resetAll().addParam("dispatcherId", id).addParam("type", type + "").addParam("pageNo", page.pageNo + "").addParam("pageSize", page.pageSize + "").setUrl(Urls.MY_ORDERS).setBaseClass(BaseData.class).setListener(l);
		logic.doPost();
//		BaseData baseData = new BaseData();
//		baseData.status = Constant.STATUS_OK;
//		MapData mapData = new MapData();
//		Page p = new Page();
//		p.totalCount = 30;
//		p.pageCount = 2;
//		mapData.page = p;
//
//		List<Order> orders = new ArrayList<Order>();
//		for (int i = 0; i < page.pageSize; i++) {
//			Order order = new Order();
//			order.id = i + 1;
//			switch (type) {
//			case 1:
//				order.status = 2;
//				break;
//
//			case 2:
//				order.status = 3;
//				break;
//				
//			case 3:
//				order.status = i % 4 + 1;
//				break;
//			}
//			
//			order.orderNum = "2015023251544" + i;
//			order.appointmentTime = "2015-08-19 09:00";
//			order.style1 = "砼车";
//			order.count = i + 1;
//			order.volume = (i + 1) * 100;
//			order.sumPrice = (i + 1) * 3000;
//			order.robCount = i + 1;
//			order.condition = "30公里以内";
//			order.conditionName = "运输距离";
//
//			List<OrderLog> orderLogs = new ArrayList<OrderLog>();
//
//			OrderLog log1 = new OrderLog();
//			Owner owner1 = new Owner();
//			Truck truck1 = new Truck();
//			truck1.style1 = new TruckStyle1(1, "砼车");
//			truck1.style2 = new TruckStyle2(1, "12方");
//			truck1.licenseplateNum = "鄂A123***";
//			owner1.name = "小张";
//			owner1.icon = "https://d13yacurqjgara.cloudfront.net/users/109605/screenshots/2152255/lion.png";
//			owner1.finishedCount = i * 10;
//			log1.truck = truck1;
//			log1.owner = owner1;
//
//			OrderLog log2 = new OrderLog();
//			Owner owner2 = new Owner();
//			Truck truck2 = new Truck();
//			truck2.style1 = new TruckStyle1(1, "砼车");
//			truck2.style2 = new TruckStyle2(1, "12方");
//			truck2.licenseplateNum = "鄂A123***";
//			owner2.name = "小王";
//			owner2.icon = "https://d13yacurqjgara.cloudfront.net/users/10009/screenshots/2152900/ffp_c.jpg";
//			owner2.finishedCount = i * 10;
//			log2.truck = truck2;
//			log2.owner = owner2;
//
//			order.orderLogs = orderLogs;
//			orders.add(order);
//		}
//
//		mapData.orders = orders;
//		baseData.data = mapData;
//		l.onResponse(baseData);
	}

	public void cancelOrder(String dispatcherId, long orderId, String orderNum, double orderSumPrice, NListener<BaseData> l) {
		logic.edit().resetAll().addParam("dispatcherId", dispatcherId).addParam("orderNum", orderNum).addParam("orderId", orderId + "").addParam("orderSumPrice", orderSumPrice + "").setBaseClass(BaseData.class).setUrl(Urls.CANCEL_ORDER).setListener(l);
		logic.doPost();
//		BaseData baseData = new BaseData();
//		baseData.status = Constant.STATUS_OK;
//		MapData mapData = new MapData();
//
//		Order order = new Order();
//		order.id = 0;
//		order.status = 4;
//
//		order.orderNum = "2015023251544";
//		order.appointmentTime = "2015-08-19 09:00";
//		order.style1 = "砼车";
//		order.count = 12;
//		order.volume = 600;
//		order.sumPrice = 18000;
//		order.conditionName = "运输距离";
//		order.condition = "30公里以内";
//
//		Station station = new Station();
//		station.name = "武汉新中环建材有限公司";
//		station.addAddress = "武汉市汉阳区汉阳大道孟家铺特1号";
//
//		Dispatcher dispatcher = new Dispatcher();
//		dispatcher.name = "王玉玺";
//		dispatcher.phone = "13000000000";
//
//		order.dispatcher = dispatcher;
//		order.station = station;
//
//		List<OrderLog> orderLogs = new ArrayList<OrderLog>();
//		for (int i = 0; i < 10; i++) {
//			OrderLog log1 = new OrderLog();
//			Owner owner1 = new Owner();
//			Truck truck1 = new Truck();
//			truck1.style1 = new TruckStyle1(1, "砼车");
//			truck1.style2 = new TruckStyle2(1, "12方");
//			truck1.licenseplateNum = "鄂A123***";
//			owner1.name = "小张";
//			owner1.icon = "https://d13yacurqjgara.cloudfront.net/users/109605/screenshots/2152255/lion.png";
//			owner1.finishedCount = 20;
//			log1.truck = truck1;
//			log1.owner = owner1;
//			OrderStatus status = new OrderStatus();
//			status.id = i;
//			log1.status = status;
//			log1.addStatus = "获赔18元";
//			orderLogs.add(log1);
//		}
//		order.orderLogs = orderLogs;
//
//		mapData.disOrderDetail = order;
//		baseData.data = mapData;
//		l.onResponse(baseData);
	}
	
	public void increateOrderPrice(long orderId, double amount, NListener<BaseData> l) {
		logic.edit().resetAll().addParam("orderId", orderId + "").addParam("amount", amount + "").setBaseClass(BaseData.class).setUrl(Urls.INCREASE_PRICE).setListener(l);
		logic.doPost();
	}
	
	public void getDamage(long orderId, NListener<BaseData> l) {
		logic.edit().resetAll().addParam("orderId", orderId + "").setBaseClass(BaseData.class).setUrl(Urls.GET_DAMAGE).setListener(l);
		logic.doPost();
	}
}
